package hadoop.hdfs.demo;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

/**
 * @author qiss
 * @create 2018-02-12 18:17
 * job.setGroupingComparatorClass(ItemidGroupingComparator.class);
 **/
public class ItemidFroupingComparator extends WritableComparator {
    protected ItemidFroupingComparator(){
        super(OrderBean.class,true);
    }

    @Override
    public int compare(WritableComparable a, WritableComparable b) {
         OrderBean aBean = (OrderBean)a;
         OrderBean bBean = (OrderBean)b;
         //将item_id相同的视为相同，聚合为一组
         return aBean.getItemid().compareTo(bBean.getItemid());
    }
}
